package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.FreeFragmentRightInfo;

/**
 * Created by lanouhn on 16/9/3.
 */
public class FreeRightSmallAdapter extends RecyclerView.Adapter<FreeRightSmallAdapter.FreeSmallHolder> {
    private Context context;
    private FreeFragmentRightInfo datas;

    public FreeRightSmallAdapter(Context context, FreeFragmentRightInfo datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public FreeSmallHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv_fragment_free, null);
        FreeSmallHolder holder = new FreeSmallHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(FreeSmallHolder holder, int position) {
        FreeFragmentRightInfo.DataBean.RecordsBean bean =
                datas.getData().getRecords().get(position);
        holder.tv_count.setText(bean.getVisitors() + "");
        holder.tv_time.setText(bean.getDay());

        FreeRightTopRvAdapter adapterTop = new FreeRightTopRvAdapter(context, bean.getItem());
        holder.recyclerView_top.setAdapter(adapterTop);


        FreeRightBottomRvAdapter bottomRvAdapter = new FreeRightBottomRvAdapter
                (context, bean.getAward_users());
        holder.recyclerView_bottom.setAdapter(bottomRvAdapter);
    }

    @Override
    public int getItemCount() {
        return datas.getData().getRecords().size();
    }

    public class FreeSmallHolder extends RecyclerView.ViewHolder {
        private RecyclerView recyclerView_top, recyclerView_bottom;
        private TextView tv_time, tv_count;

        public FreeSmallHolder(View itemView) {
            super(itemView);
            recyclerView_top = (RecyclerView) itemView.findViewById(R.id.rv_item_free_top);
            recyclerView_bottom = (RecyclerView) itemView.findViewById(R.id.rv_item_free_bottom);
            tv_time = (TextView) itemView.findViewById(R.id.tv_item_free_time);
            tv_count = (TextView) itemView.findViewById(R.id.tv_item_free_counts);

            LinearLayoutManager manager = new LinearLayoutManager(context);
            manager.setOrientation(LinearLayoutManager.HORIZONTAL);
            recyclerView_top.setLayoutManager(manager);


            LinearLayoutManager manager1 = new LinearLayoutManager(context);
            manager1.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView_bottom.setLayoutManager(manager1);
        }
    }

}
